{extend name="public:base" /}
{block name="header"}
<style>
    .form input{
        width:300px;
        padding:5px;
    }
    .form input:focus{
        border:1px solid #ff0000;
    }
    .signup_now{
         padding:5px 20px;
         background-color: #0b6fa2;
         color:#fff;
        border-bottom:3px solid #0b6fa2;
     }
    .signup_now a{
        color:#fff;
    }
    .signup_other{
        border-bottom:3px solid #0b6fa2;
        padding:5px 20px;
    }
</style>
{/block}
{block name="main"}
    <div class="ShareAnyContainer" style="font-size: 14px;">
        当前位置：<a href="/" title="首页">首页</a>&nbsp;&nbsp;/&nbsp;&nbsp;<a href="{:url('shop/login/register')}" title="注册">注册</a>
    </div>
    <div class="ShareAnySeparate"></div>
    <div class="ShareAnyContainer">
        <div class="line"></div>
    </div>
    <div class="ShareAnySeparate"></div>
    <div class="ShareAnyContainer form" style="line-height: 50px; text-align: center;">
        <p>
        	<span class="signup_now">
        		<a href="{:url('shop/login/register')}" title="手机注册">手机注册</a>
        	</span>
        	<span class="signup_other">
        		<a href="{:url('shop/login/registerEmail')}" title="邮箱注册">邮箱注册</a>
        	</span>
        </p>
        <p>
        	手机号码：<input type="text" id="phone">
        </p>
        <p>
           <input type="button" id="getcode" style="width: 233px;" value="获取验证码" />
        </p>
        <p>验证码：&nbsp;&nbsp;&nbsp;<input type="text" id="code"></p>
        <p>登录密码：<input type="password" id="password"></p>
        <p>确认密码：<input type="password" id="repassword"></p>
        <p>
            <button id="submit" style="padding:10px 25px;">同意网站会员注册协议并注册</button>
            <br>
            <a target="_blank" href="{:url('shop/login/read')}" title="网站会员注册协议">网站会员注册协议</a>
        </p>
    </div>
{/block}
{block name="footer"}
<script type="text/javascript">
	$(function() {
		var countdown=120; 

		$('#submit').click(function(){
				var phone = $('#phone').val();
				var code = $('#code').val();
				var password = $('#password').val();
				var repassword = $('#repassword').val();
				if( phone == '' || phone.match(/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/) == null){
					alert('手机号格式不正确');return false;
				}else if(code == ''){
					alert('验证码不能为空');return false;
				}else if(password != repassword || password == ''){
					alert('两次密码输入不一致');return false;
				}

				if(code != ''){
					$.post("{:url('shop/login/getcode')}",{phone:phone, code:code},function(res){
							if(res.code != 0){
								alert(res.msg);return false;
							}else{
								//验证成功 提交注册
								$.post("{:url('shop/login/register')}", {phone:phone, code:code, password:password}, function(obj){
										if(obj.code == 0){
											alert(obj.msg);
											window.location.href = "{:url('shop/login/index')}";
										}else{
											alert(obj.msg);
										}
								},'json')
							}
					})
				}
		});

		$('#getcode').click(function(){
				var phone = $("#phone").val();
				if(phone == ''){
					alert('请输入手机号'); return false;
				}
				$.get("{:url('shop/login/sendcode')}",{'phone': phone},function(ev){
					//倒计时
					settime($('#getcode'));
				});
		});

		function settime(obj) { //发送验证码倒计时
		    if (countdown == 0) { 
		        obj.attr('disabled',false); 
		        //obj.removeattr("disabled"); 
		        obj.val("免费获取验证码");
		        countdown = 60; 
		        return;
		    } else { 
		        obj.attr('disabled',true);
		        obj.val("重新发送(" + countdown + ")");
		        countdown--; 
		    } 
			setTimeout(function() { 
		    settime(obj) }
		    ,1000) 
		}
	});
</script>
{/block}